package java_learn.java_jinjie.ThreadSafe;

/**
 * @Author: 李浩然
 * @Date: 2020/12/21 12:21 上午
 */
public class Chiho extends Thread {
    private Baozi bz;

    public Chiho(Baozi bz) {
        this.bz = bz;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (bz) {
                if (bz.flag == false) {
                    try {
                        bz.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                //被唤醒之后
                System.out.println("正在吃" + bz.pi + bz.xian);
                bz.flag = false;
                bz.notify();
                System.out.println("吃货吃完了" + bz.pi + bz.xian + "包子开始生产了");
            }
        }
    }
}
